//
//  YZCommunityLocationViewModel.m
//  VET
//
//  Created by YZ on 2018/7/11.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZCommunityLocationViewModel.h"
#import "YZMapManager.h"

@interface YZCommunityLocationViewModel()

@property (nonatomic, strong) YZMapManager *mapManager;

@end

@implementation YZCommunityLocationViewModel

@synthesize dataSource = _dataSource;

- (instancetype)init
{
    if(self = [super init]){
        [self config];
    }
    return self;
}

- (void)config
{
    
}

- (void)startRequestCommunityLocationWithCoor:(CLLocationCoordinate2D)coor
{
    self.loading = YES;
    YZCommunityLocationNoneModel *noneModel = [YZCommunityLocationNoneModel new];
    noneModel.addressName = @"不显示位置";
    NSMutableArray *arr = [NSMutableArray array];
    _dataSource = @[arr];
    [self.mapManager startSearchPOSWithCoor:coor result:^(BOOL success, NSArray<AMapPOI *> *resultObjs)  {
        if (success) {
            [arr addObject:noneModel];
            for (AMapPOI *poi in resultObjs) {
                YZCommunityLocationModel *locationModel = [YZCommunityLocationModel new];
                locationModel.addressName = poi.name;
                locationModel.address = [NSString stringWithFormat:@"%@%@%@",poi.province,poi.city,poi.address];
                [arr addObject:locationModel];
            }
            self.loading = NO;
        }else
        {
            [arr addObject:noneModel];
            self.loading = NO;
        }
    }];
}

- (YZMapManager *)mapManager
{
    if (!_mapManager) {
        _mapManager = [[YZMapManager alloc] init];
    }
    return _mapManager;
}

@end
